import {testNetWork} from "./env"
import { ethers, providers, utils } from "ethers";
export async function issueToken() {
    const main = async () => {
      const provider = new ethers.providers.JsonRpcProvider(testNetWork)
      const privateKey = '5e34716a60a0926d67c629fae8752cdc9fbe742095a093d40e5b1a2834cc981e'
      const wallet = new ethers.Wallet(privateKey, provider)
      const abiERC20 = [
        "constructor(string memory name_, string memory symbol_)",
        "function name() view returns (string)",
        "function symbol() view returns (string)",
        "function totalSupply() view returns (uint256)",
        "function balanceOf(address) view returns (uint)",
        "function transfer(address to, uint256 amount) external returns (bool)",
        "function mint(uint amount) external",
      ];
      // const byteCode = '60806040526012600560006101000a81548160ff021916908360ff1602179055503480156200002d57600080fd5b506040516200133f3803806200133f833981810160405281019062000053919062000212565b8160039081620000649190620004e2565b508060049081620000769190620004e2565b505050620005c9565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000e8826200009d565b810181811067ffffffffffffffff821117156200010a5762000109620000ae565b5b80604052505050565b60006200011f6200007f565b90506200012d8282620000dd565b919050565b600067ffffffffffffffff82111562000150576200014f620000ae565b5b6200015b826200009d565b9050602081019050919050565b60005b83811015620001885780820151818401526020810190506200016b565b60008484015250505050565b6000620001ab620001a58462000132565b62000113565b905082815260208101848484011115620001ca57620001c962000098565b5b620001d784828562000168565b509392505050565b600082601f830112620001f757620001f662000093565b5b81516200020984826020860162000194565b91505092915050565b600080604083850312156200022c576200022b62000089565b5b600083015167ffffffffffffffff8111156200024d576200024c6200008e565b5b6200025b85828601620001df565b925050602083015167ffffffffffffffff8111156200027f576200027e6200008e565b5b6200028d85828601620001df565b9150509250929050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680620002ea57607f821691505b6020821081036200030057620002ff620002a2565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026200036a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826200032b565b6200037686836200032b565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003c3620003bd620003b7846200038e565b62000398565b6200038e565b9050919050565b6000819050919050565b620003df83620003a2565b620003f7620003ee82620003ca565b84845462000338565b825550505050565b600090565b6200040e620003ff565b6200041b818484620003d4565b505050565b5b8181101562000443576200043760008262000404565b60018101905062000421565b5050565b601f82111562000492576200045c8162000306565b62000467846200031b565b8101602085101562000477578190505b6200048f62000486856200031b565b83018262000420565b50505b505050565b600082821c905092915050565b6000620004b76000198460080262000497565b1980831691505092915050565b6000620004d28383620004a4565b9150826002028217905092915050565b620004ed8262000297565b67ffffffffffffffff811115620005095762000508620000ae565b5b620005158254620002d1565b6200052282828562000447565b600060209050601f8311600181146200055a576000841562000545578287015190505b620005518582620004c4565b865550620005c1565b601f1984166200056a8662000306565b60005b8281101562000594578489015182556001820191506020850194506020810190506200056d565b86831015620005b45784890151620005b0601f891682620004a4565b8355505b6001600288020188555050505b505050505050565b610d6680620005d96000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c806342966c681161007157806342966c681461016857806370a082311461018457806395d89b41146101b4578063a0712d68146101d2578063a9059cbb146101ee578063dd62ed3e1461021e576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b661024e565b6040516100c391906109ba565b60405180910390f35b6100e660048036038101906100e19190610a75565b6102dc565b6040516100f39190610ad0565b60405180910390f35b6101046103ce565b6040516101119190610afa565b60405180910390f35b610134600480360381019061012f9190610b15565b6103d4565b6040516101419190610ad0565b60405180910390f35b610152610583565b60405161015f9190610b84565b60405180910390f35b610182600480360381019061017d9190610b9f565b610596565b005b61019e60048036038101906101999190610bcc565b61066d565b6040516101ab9190610afa565b60405180910390f35b6101bc610685565b6040516101c991906109ba565b60405180910390f35b6101ec60048036038101906101e79190610b9f565b610713565b005b61020860048036038101906102039190610a75565b6107ea565b6040516102159190610ad0565b60405180910390f35b61023860048036038101906102339190610bf9565b610905565b6040516102459190610afa565b60405180910390f35b6003805461025b90610c68565b80601f016020809104026020016040519081016040528092919081815260200182805461028790610c68565b80156102d45780601f106102a9576101008083540402835291602001916102d4565b820191906000526020600020905b8154815290600101906020018083116102b757829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516103bc9190610afa565b60405180910390a36001905092915050565b60025481565b600081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104629190610cc8565b92505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104b79190610cc8565b92505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461050c9190610cfc565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516105709190610afa565b60405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105e49190610cc8565b9250508190555080600260008282546105fd9190610cc8565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516106629190610afa565b60405180910390a350565b60006020528060005260406000206000915090505481565b6004805461069290610c68565b80601f01602080910402602001604051908101604052809291908181526020018280546106be90610c68565b801561070b5780601f106106e05761010080835404028352916020019161070b565b820191906000526020600020905b8154815290600101906020018083116106ee57829003601f168201915b505050505081565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546107619190610cfc565b92505081905550806002600082825461077a9190610cfc565b925050819055503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516107df9190610afa565b60405180910390a350565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461083a9190610cc8565b92505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461088f9190610cfc565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516108f39190610afa565b60405180910390a36001905092915050565b6001602052816000526040600020602052806000526040600020600091509150505481565b600081519050919050565b600082825260208201905092915050565b60005b83811015610964578082015181840152602081019050610949565b60008484015250505050565b6000601f19601f8301169050919050565b600061098c8261092a565b6109968185610935565b93506109a6818560208601610946565b6109af81610970565b840191505092915050565b600060208201905081810360008301526109d48184610981565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610a0c826109e1565b9050919050565b610a1c81610a01565b8114610a2757600080fd5b50565b600081359050610a3981610a13565b92915050565b6000819050919050565b610a5281610a3f565b8114610a5d57600080fd5b50565b600081359050610a6f81610a49565b92915050565b60008060408385031215610a8c57610a8b6109dc565b5b6000610a9a85828601610a2a565b9250506020610aab85828601610a60565b9150509250929050565b60008115159050919050565b610aca81610ab5565b82525050565b6000602082019050610ae56000830184610ac1565b92915050565b610af481610a3f565b82525050565b6000602082019050610b0f6000830184610aeb565b92915050565b600080600060608486031215610b2e57610b2d6109dc565b5b6000610b3c86828701610a2a565b9350506020610b4d86828701610a2a565b9250506040610b5e86828701610a60565b9150509250925092565b600060ff82169050919050565b610b7e81610b68565b82525050565b6000602082019050610b996000830184610b75565b92915050565b600060208284031215610bb557610bb46109dc565b5b6000610bc384828501610a60565b91505092915050565b600060208284031215610be257610be16109dc565b5b6000610bf084828501610a2a565b91505092915050565b60008060408385031215610c1057610c0f6109dc565b5b6000610c1e85828601610a2a565b9250506020610c2f85828601610a2a565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610c8057607f821691505b602082108103610c9357610c92610c39565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610cd382610a3f565b9150610cde83610a3f565b9250828203905081811115610cf657610cf5610c99565b5b92915050565b6000610d0782610a3f565b9150610d1283610a3f565b9250828201905080821115610d2a57610d29610c99565b5b9291505056fea2646970667358221220bb723bdb98b504df51966c0f1ed151c5a506904211302f123cf97e9fe261648e64736f6c63430008120033'
      // 1. 创建合约工厂
      // const contractFactor = new ethers.ContractFactory(abiERC20,byteCode,wallet)
      // 2. 创建合约实例
      // const contract = await contractFactor.deploy('vscode', 'vscode')

      // console.log(`合约的地址${await contract.address}`)
      // console.log(`合约的名字${await contract.name()}`)
      // console.log(`合约的名字${await contract.symbol()}`)
      // // 3. 等待合约部署到链上
      // console.log('将合约部署到链上')
      
      // await contract.deployed()
      
      // console.log('合约部署完成')
      const address = '0x90fe5d0d4d012F72772f97495A94128B96C4c7E6'
      const contract = new ethers.Contract(address,abiERC20,wallet)
      console.log(`合约的名称,${await contract.name()}`)
      // await contract.mint(1000)
      const walletAddress = await wallet.getAddress()
      console.log('walletAddress',walletAddress)
      const balance = await contract.balanceOf(walletAddress)
      console.log('当前钱包的余额', balance.toNumber())
      const totalSupply = await contract.totalSupply()
      console.log('当前合约币总供应量', totalSupply.toNumber())
      //  给以太坊创世人 钱包转点我们铸造的币
      const transfer = await contract.transfer('vitalik.eth',1500)

      const balanceVitalik = await contract.balanceOf('vitalik.eth')
      console.log('vitalik.eth 持有多少我们铸造的币', balanceVitalik.toNumber())
    }
    main()
}